package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserParam;
import com.tarena.lbs.user.pojo.param.UserTagsParam;
import com.tarena.lbs.user.pojo.query.UserQuery;
import com.tarena.lbs.user.pojo.vo.UserVO;
import com.tarena.lbs.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.jni.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 手机小程序用户处理
 */
@Api(tags = "用户接口")
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户注册")
    //小程序新增注册
    @PostMapping("/basic/user/info/register")
    public Result<Void> register(@RequestBody UserParam param) throws BusinessException{
        log.info("用户注册参数:{}",param);
        userService.reg(param);
        return Result.success();
    }

    //解析jwt 拿到id获取登录用户性情
    @ApiOperation(value = "用户详情")
    @GetMapping("/basic/user/detail")
    public Result<UserVO> detail()throws BusinessException{
        log.info("用户详情控制层");
        UserVO userVO = userService.detail();
        return new  Result<>(userVO);
    }


    //用户提交绑定关联所选标签
    @ApiOperation(value = "用户标签关联")
    @GetMapping("/basic/user/tag")
    public Result<Void> bindUserTags(UserTagsParam param) throws BusinessException{
        log.info("用户标签关联参数:{}",param);
        userService.bindUserTags(param);
        return Result.success();
    }

    //用户列表展示
    @ApiOperation(value = "用户列表展示")
    @PostMapping("/admin/basic/user/list")
    public Result<PageResult<UserVO>> showList(@RequestBody UserQuery userQuery)throws BusinessException{
        log.info("用户列表入参{}",userQuery);
        PageResult<UserVO> result = userService.showList(userQuery);
        return new Result<>(result);
    }

}
